package com.jijuxie.house.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jijuxie.house.domain.HouseAssign;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 房源分配数据访问层
 * 
 * @author jijuxie
 */
public interface HouseAssignMapper extends BaseMapper<HouseAssign> {

    /**
     * 获取房源的经纪人分配情况
     * 
     * @param houseId 房源ID
     * @return 分配记录列表
     */
    @Select("SELECT * FROM house_assign WHERE house_id = #{houseId} AND status = '1'")
    List<HouseAssign> selectAssignsByHouseId(@Param("houseId") Long houseId);

    /**
     * 获取经纪人负责的房源分配情况
     * 
     * @param agentId 经纪人ID
     * @return 分配记录列表
     */
    @Select("SELECT * FROM house_assign WHERE agent_id = #{agentId} AND status = '1'")
    List<HouseAssign> selectAssignsByAgentId(@Param("agentId") Long agentId);

    /**
     * 取消分配关系
     * 
     * @param houseId 房源ID
     * @param agentId 经纪人ID
     * @return 影响行数
     */
    @Update("UPDATE house_assign SET status = '0', update_time = NOW() WHERE house_id = #{houseId} AND agent_id = #{agentId}")
    int cancelAssign(@Param("houseId") Long houseId, @Param("agentId") Long agentId);
} 